package site.timers.chat.pojo;

import lombok.Data;
import site.timers.chat.exception.ApplicationException;

/**
 * @Classname Result
 * @Description TODO
 * @Version 1.0.0
 * @Date 2025/8/18 14:22
 * @Author twl
 */
@Data
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(Integer code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> error(String message) {
        return Result.error(500, message);
    }

    public static <T> Result<T> error(ApplicationException e) {
        return Result.error(e.getCode(), e.getMsg());
    }
}
